Adding 'no-matches' signal support to gtkentrycompletion
authorSaurabh <srp201201051@gmail.com>
Fri, 27 Jun 2014 16:41:09 +0000 (22:11 +0530)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 28 Jun 2014 04:41:09 +0000 (00:41 -0400)
Add a new 'no-matches' signal and add a function pointer to gtkentrycompletionclass
and remove one from the padding at the end.

https://bugzilla.gnome.org/show_bug.cgi?id=726566

gtk/gtkentrycompletion.c
gtk/gtkentrycompletion.h

index e4d5736a6abbd09ef380c6d64f7d5f7dd5418f26..9bd55f894e759d7725337f2fe0ffb0b67f921764 100644 (file)
@@ -98,6 +98,7 @@ enum
   MATCH_SELECTED,
   ACTION_ACTIVATED,
   CURSOR_ON_MATCH,
+  NO_MATCHES,
   LAST_SIGNAL
 };
 
@@ -211,6 +212,7 @@ gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
   klass->match_selected = gtk_entry_completion_match_selected;
   klass->insert_prefix = gtk_entry_completion_real_insert_prefix;
   klass->cursor_on_match = gtk_entry_completion_cursor_on_match;
+  klass->no_matches = NULL;
 
   /**
    * GtkEntryCompletion::insert-prefix:
@@ -298,6 +300,26 @@ gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
                   GTK_TYPE_TREE_MODEL,
                   GTK_TYPE_TREE_ITER);
 
+  /**
+   * GtkEntryCompletion::no-matches:
+   * @widget: the object which received the signal
+   *
+   * Gets emitted when the filter model has zero
+   * number of rows in completion_complete method.
+   * (In other words when GtkEntryCompletion is out of
+   *  suggestions)
+   *
+   * Since: 3.14
+   */
+  entry_completion_signals[NO_MATCHES] =
+    g_signal_new (I_("no-matches"),
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (GtkEntryCompletionClass, no_matches),
+                  NULL, NULL,
+                  NULL,
+                  G_TYPE_NONE, 0);
+
   /**
    * GtkEntryCompletion::action-activated:
    * @widget: the object which received the signal
@@ -1256,6 +1278,7 @@ void
 gtk_entry_completion_complete (GtkEntryCompletion *completion)
 {
   gchar *tmp;
+  GtkTreeIter iter;
 
   g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
   g_return_if_fail (GTK_IS_ENTRY (completion->priv->entry));
@@ -1272,6 +1295,9 @@ gtk_entry_completion_complete (GtkEntryCompletion *completion)
 
   gtk_tree_model_filter_refilter (completion->priv->filter_model);
 
+  if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (completion->priv->filter_model), &iter))
+    g_signal_emit (completion, entry_completion_signals[NO_MATCHES], 0);
+
   if (gtk_widget_get_visible (completion->priv->popup_window))
     _gtk_entry_completion_resize_popup (completion);
 }
index 69f74c8629afdbe8003393b948ed726c5435e920..d0f5d08e6d9ebc40ba8762483b555e8eb41d8132 100644 (file)
@@ -87,12 +87,12 @@ struct _GtkEntryCompletionClass
   gboolean (* cursor_on_match)  (GtkEntryCompletion *completion,
                                  GtkTreeModel       *model,
                                  GtkTreeIter        *iter);
+  void     (* no_matches)       (GtkEntryCompletion *completion);
 
   /* Padding for future expansion */
   void (*_gtk_reserved0) (void);
   void (*_gtk_reserved1) (void);
   void (*_gtk_reserved2) (void);
-  void (*_gtk_reserved3) (void);
 };
 
 /* core */